/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.firestorm.traficforecast.astar;

import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.firestorm.traficforecast.database.MySQLConnect;
import org.firestorm.traficforecast.database.Road;
import org.firestorm.traficforecast.database.RoadDAO;

/**
 *
 * @author HMT
 */
public class Test {
    public static void main(String[] args) {
    	DateFormat df = new SimpleDateFormat("yyyy/mm/dd HH:mm:ss");
    	Date time = new Date();
    	System.out.println(df.format(time));
        FindWay fw = new FindWay();
        MySQLConnect.connectToDb("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/traficforecast", "root", "123456");

//    	Road start = RoadDAO.getRoad("1170807501");
//    	Road finish = RoadDAO.getRoad("3608713401");
        
    	Road start = RoadDAO.getRoadbyName("Mã Mây");
    	Road finish = RoadDAO.getRoadbyName("Lê Trọng Tấn");
    	System.out.println(start.getLen());
    	
        System.out.println(start.getName() + " to " + finish.getName());
        ArrayList<Road> vd = fw.aStar(start, finish);
        try {
            MySQLConnect.con.close();
        } catch (SQLException ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
        for(int i=0;i<vd.size()-1;i++){
            if(!(vd.get(i).getName().equals(vd.get(i+1).getName()))){
                System.out.print(vd.get(i).getName() +"("+ vd.get(i).getStatus() +")");
                System.out.print("==>");
            }           
            
        }
        if(vd.isEmpty()){
            System.out.println("Không tìm thấy đường");
        }else{
            System.out.print(vd.get(vd.size()-1).getName());
        }
        time = new Date();
    	System.out.println("\n" + df.format(time));
    }
}
